import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
// 自定义的 导航组件 来替换以前的组件Link(该link 组件是react-router-dom 自带的)
class Mynav extends Component {
    render() {
        console.log('Mynav', this.props);
        let url = this.props.to;  // 为要跳转的路由地址
        let content = this.props.children
        let Tag = this.props.tag ? this.props.tag : 'a'
        // console.log(Tag);
        return (
            <Tag onClick={() => this.gotopage(url)}>
                {content}
            </Tag>
        );
    }
    // 路由跳转的事件
    gotopage(path) {
        console.log(this);
        // 使用编程式导航实现路由的跳转
        this.props.history.push(path)
    }

}

export default withRouter(Mynav);
